package com.galeno.redis;

import redis.clients.jedis.BitOP;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @author galeno
 * @Title:
 * @Description:
 * @date 2021/9/1422:28
 */
public class RedisBitMapDemo {
    public static void main(String[] args) {
        JedisPool pool = new JedisPool("galeno01", 6379);
        Jedis jedis = pool.getResource();
        jedis.flushDB();
        jedis.setbit("a",0,"0");
        jedis.setbit("a",1,"1");
        jedis.setbit("a",2,"1");
        jedis.setbit("a",3,"1");
        jedis.setbit("a",4,"1");
        jedis.setbit("a",5,"1");
        jedis.setbit("a",6,"1");
        jedis.setbit("a",16,"1");


        jedis.setbit("b",0,"0");
        jedis.setbit("b",1,"1");
        jedis.setbit("b",2,"0");
        jedis.setbit("b",3,"1");
        jedis.setbit("b",16,"0");

        /**
         * start  end指的是字节的偏移量
         */
        Long a = jedis.bitcount("a", 0, 1);
        System.out.println(a);


        Long a1 = jedis.bitcount("a");
        System.out.println(a1+"个1");
        // 对两个bitmap操作
        System.out.println(jedis.bitop(BitOP.AND, "a", "b"));
        System.out.println(jedis.bitop(BitOP.NOT, "a", "b"));
        System.out.println(jedis.bitop(BitOP.OR, "a", "b"));
        System.out.println(jedis.bitop(BitOP.XOR, "a", "b"));


    }
}
